﻿

using System.Data;
using System.Data.Common;
using System.Data.Entity;
namespace Datos
{
    public class Repository<C> where C : DbContext, new()
    {
        C context;
        //DbContextTransaction trn;
        //DbTransaction trn;
        public Repository()
        {
            context = new C();
        }

        public E Create<E>() where E : class ,new()
        {
            return new E();
        }

        public void Insert<E>(E entity) where E : class
        {
            context.Entry(entity).State = EntityState.Added;
        }

        public void Delete<E>(E entity) where E : class
        {
            context.Entry(entity).State = EntityState.Deleted;
        }

        public void Update<E>(E entity) where E : class
        {
            context.Entry(entity).State = EntityState.Modified;
        }

        public int Save()
        {
            return context.SaveChanges();
        }

        //public void BeginTransaction(System.Data.IsolationLevel isolationLevel)
        public void BeginTransaction()
        {
            context.Database.Connection.Open();
            //  trn = context.Database.BeginTransaction();2013
            //trn = context.Database.BeginTransaction();
        }
    }
}
